package io.gitee.zhangbinhub.acp.cloud

import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled
import com.alibaba.cloud.nacos.loadbalancer.DefaultLoadBalancerAlgorithm
import com.alibaba.cloud.nacos.loadbalancer.LoadBalancerAlgorithm
import io.gitee.zhangbinhub.acp.cloud.conf.AcpCloudLoadBalancerConfiguration
import io.gitee.zhangbinhub.acp.cloud.loadbalancer.AcpCloudNacosLoadBalancerClientConfiguration
import io.gitee.zhangbinhub.acp.cloud.loadbalancer.ConditionalOnAcpLoadBalancer
import org.springframework.boot.autoconfigure.AutoConfiguration
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients
import org.springframework.context.annotation.Bean

@AutoConfiguration
@ConditionalOnAcpLoadBalancer
@ConditionalOnDiscoveryEnabled
@ConditionalOnNacosDiscoveryEnabled
@LoadBalancerClients(defaultConfiguration = [AcpCloudNacosLoadBalancerClientConfiguration::class])
@EnableConfigurationProperties(AcpCloudLoadBalancerConfiguration::class)
class AcpCloudLoadBalancerAutoConfiguration {
    @Bean
    fun defaultLoadBalancerAlgorithm(): LoadBalancerAlgorithm {
        return DefaultLoadBalancerAlgorithm()
    }
}